package com.qmerak.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.qmerak.dao.impl.LogoffDao;
import com.qmerak.dao.impl.MemberDao;
import com.qmerak.entity.LogoffEntity;
import com.qmerak.entity.MemberEntity;
import com.qmerak.service.ILogoffService;

/**
 * @author shaohong.cheng
 * @date 2013-6-25
 */
@Service
public class LogoffServiceImpl implements ILogoffService {
	@Autowired
	private LogoffDao logoffDao;
	@Autowired
	private MemberDao memberDao;

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.qmerak.service.ILogoffService#add(com.qmerak.entity.LogoffEntity)
	 */
	@Override
	public LogoffEntity add(LogoffEntity entity) {
		LogoffEntity loe = logoffDao.add(entity);
		MemberEntity memberEntity = memberDao.find(entity.getMemberID());
		memberEntity.setLogoff(loe.getId());
		memberEntity.setStatus(MemberEntity.Member_Status.LOGOFFING.name());
		memberDao.update(memberEntity);
		return loe;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.qmerak.service.ILogoffService#lastLogoff(java.lang.String)
	 */
	@Override
	public LogoffEntity lastLogoff(String memberID) {
		return logoffDao.lastLogoff(memberID);
	}

}
